home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / LOCKD / LOCKD.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  6KB  |  197 lines

  1. /*
  2.  * linux/include/linux/lockd/lockd.h
  3.  *
  4.  * General-purpose lockd include file.
  5.  *
  6.  * Copyright (C) 1996 Olaf Kirch <okir@monad.swb.de>
  7.  */
  8.  
  9. #ifndef LINUX_LOCKD_LOCKD_H
  10. #define LINUX_LOCKD_LOCKD_H
  11.  
  12. #ifdef __KERNEL__
  13.  
  14. #include <linux/in.h>
  15. #include <linux/fs.h>
  16. #include <linux/utsname.h>
  17. #include <linux/nfsd/nfsfh.h>
  18. #include <linux/lockd/bind.h>
  19. #include <linux/lockd/xdr.h>
  20. #include <linux/lockd/debug.h>
  21.  
  22. /*
  23.  * Version string
  24.  */
  25. #define LOCKD_VERSION        "0.4"
  26.  
  27. /*
  28.  * Default timeout for RPC calls (seconds)
  29.  */
  30. #define LOCKD_DFLT_TIMEO    10
  31.  
  32. /*
  33.  * Lockd host handle (used both by the client and server personality).
  34.  */
  35. struct nlm_host {
  36.     struct nlm_host *    h_next;        /* linked list (hash table) */
  37.     struct sockaddr_in    h_addr;        /* peer address */
  38.     struct svc_client *    h_exportent;    /* NFS client */
  39.     struct rpc_clnt    *    h_rpcclnt;    /* RPC client to talk to peer */
  40.     char            h_name[20];    /* remote hostname */
  41.     u32            h_version;    /* interface version */
  42.     unsigned short        h_proto;    /* transport proto */
  43.     unsigned short        h_authflavor;    /* RPC authentication type */
  44.     unsigned short        h_reclaiming : 1,
  45.                 h_inuse      : 1,
  46.                 h_monitored  : 1;
  47.     struct wait_queue *    h_gracewait;    /* wait while reclaiming */
  48.     u32            h_state;    /* pseudo-state counter */
  49.     u32            h_nsmstate;    /* true remote NSM state */
  50.     unsigned int        h_count;    /* reference count */
  51.     struct semaphore    h_sema;        /* mutex for pmap binding */
  52.     unsigned long        h_nextrebind;    /* next portmap call */
  53.     unsigned long        h_expires;    /* eligible for GC */
  54. };
  55.  
  56. /*
  57.  * Memory chunk for NLM client RPC request.
  58.  */
  59. #define NLMCLNT_OHSIZE        (sizeof(system_utsname.nodename)+10)
  60. struct nlm_rqst {
  61.     unsigned int        a_flags;    /* initial RPC task flags */
  62.     struct nlm_host *    a_host;        /* host handle */
  63.     struct nlm_args        a_args;        /* arguments */
  64.     struct nlm_res        a_res;        /* result */
  65.     char            a_owner[NLMCLNT_OHSIZE];
  66. };
  67.  
  68. /*
  69.  * This struct describes a file held open by lockd on behalf of
  70.  * an NFS client.
  71.  */
  72. struct nlm_file {
  73.     struct nlm_file *    f_next;        /* linked list */
  74.     struct knfs_fh        f_handle;    /* NFS file handle */
  75.     struct file        f_file;        /* VFS file pointer */
  76.     struct nlm_share *    f_shares;    /* DOS shares */
  77.     struct nlm_block *    f_blocks;    /* blocked locks */
  78.     unsigned int        f_locks;    /* guesstimate # of locks */
  79.     unsigned int        f_count;    /* reference count */
  80.     struct semaphore    f_sema;        /* avoid concurrent access */
  81. };
  82.  
  83. /*
  84.  * This is a server block (i.e. a lock requested by some client which
  85.  * couldn't be granted because of a conflicting lock).
  86.  */
  87. #define NLM_NEVER        (~(unsigned long) 0)
  88. struct nlm_block {
  89.     struct nlm_block *    b_next;        /* linked list (all blocks) */
  90.     struct nlm_block *    b_fnext;    /* linked list (per file) */
  91.     struct nlm_rqst        b_call;        /* RPC args & callback info */
  92.     struct svc_serv *    b_daemon;    /* NLM service */
  93.     struct nlm_host *    b_host;        /* host handle for RPC clnt */
  94.     unsigned long        b_when;        /* next re-xmit */
  95.     unsigned int        b_id;        /* block id */
  96.     unsigned char        b_queued;    /* re-queued */
  97.     unsigned char        b_granted;    /* VFS granted lock */
  98.     unsigned char        b_incall;    /* doing callback */
  99.     unsigned char        b_done;        /* callback complete */
  100.     struct nlm_file *    b_file;        /* file in question */
  101. };
  102.  
  103. /*
  104.  * Valid actions for nlmsvc_traverse_files
  105.  */
  106. #define NLM_ACT_CHECK        0        /* check for locks */
  107. #define NLM_ACT_MARK        1        /* mark & sweep */
  108. #define NLM_ACT_UNLOCK        2        /* release all locks */
  109.  
  110. /*
  111.  * Global variables
  112.  */
  113. extern struct rpc_program    nlm_program;
  114. extern struct svc_procedure    nlmsvc_procedures[];
  115. extern unsigned long        nlmsvc_grace_period;
  116. extern unsigned long        nlmsvc_timeout;
  117.  
  118. /*
  119.  * Lockd client functions
  120.  */
  121. struct nlm_rqst * nlmclnt_alloc_call(void);
  122. int          nlmclnt_call(struct nlm_rqst *, u32);
  123. int          nlmclnt_async_call(struct nlm_rqst *, u32, rpc_action);
  124. int          nlmclnt_block(struct nlm_host *, struct file_lock *, u32 *);
  125. int          nlmclnt_cancel(struct nlm_host *, struct file_lock *);
  126. u32          nlmclnt_grant(struct nlm_lock *);
  127. void          nlmclnt_recovery(struct nlm_host *, u32);
  128. int          nlmclnt_reclaim(struct nlm_host *, struct file_lock *);
  129. int          nlmclnt_setgrantargs(struct nlm_rqst *, struct nlm_lock *);
  130. void          nlmclnt_freegrantargs(struct nlm_rqst *);
  131.  
  132. /*
  133.  * Host cache
  134.  */
  135. struct nlm_host * nlmclnt_lookup_host(struct sockaddr_in *, int, int);
  136. struct nlm_host * nlmsvc_lookup_host(struct svc_rqst *);
  137. struct nlm_host * nlm_lookup_host(struct svc_client *,
  138.                     struct sockaddr_in *, int, int);
  139. struct rpc_clnt * nlm_bind_host(struct nlm_host *);
  140. void          nlm_rebind_host(struct nlm_host *);
  141. void          nlm_release_host(struct nlm_host *);
  142. void          nlm_shutdown_hosts(void);
  143.  
  144. /*
  145.  * Server-side lock handling
  146.  */
  147. u32          nlmsvc_lock(struct svc_rqst *, struct nlm_file *,
  148.                     struct nlm_lock *, int, struct nlm_cookie *);
  149. u32          nlmsvc_unlock(struct nlm_file *, struct nlm_lock *);
  150. u32          nlmsvc_testlock(struct nlm_file *, struct nlm_lock *,
  151.                     struct nlm_lock *);
  152. u32          nlmsvc_cancel_blocked(struct nlm_file *, struct nlm_lock *);
  153. unsigned long      nlmsvc_retry_blocked(void);
  154. int          nlmsvc_traverse_blocks(struct nlm_host *, struct nlm_file *,
  155.                     int action);
  156.  
  157. /*
  158.  * File handling for the server personality
  159.  */
  160. u32          nlm_lookup_file(struct svc_rqst *, struct nlm_file **,
  161.                     struct nfs_fh *);
  162. void          nlm_release_file(struct nlm_file *);
  163. void          nlmsvc_mark_resources(void);
  164. void          nlmsvc_free_host_resources(struct nlm_host *);
  165.  
  166. extern __inline__ struct inode *
  167. nlmsvc_file_inode(struct nlm_file *file)
  168. {
  169.     return file->f_file.f_dentry->d_inode;
  170. }
  171.  
  172. /*
  173.  * Compare two host addresses (needs modifying for ipv6)
  174.  */
  175. extern __inline__ int
  176. nlm_cmp_addr(struct sockaddr_in *sin1, struct sockaddr_in *sin2)
  177. {
  178.     return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
  179. }
  180.  
  181. /*
  182.  * Compare two NLM locks.
  183.  * When the second lock is of type F_UNLCK, this acts like a wildcard.
  184.  */
  185. extern __inline__ int
  186. nlm_compare_locks(struct file_lock *fl1, struct file_lock *fl2)
  187. {
  188.     return    fl1->fl_pid   == fl2->fl_pid
  189.          && fl1->fl_start == fl2->fl_start
  190.          && fl1->fl_end   == fl2->fl_end
  191.          &&(fl1->fl_type  == fl2->fl_type || fl2->fl_type == F_UNLCK);
  192. }
  193.  
  194. #endif /* __KERNEL__ */
  195.  
  196. #endif /* LINUX_LOCKD_LOCKD_H */
  197.